package com.example.lushudao_admin.service.impl;

import com.example.lushudao_admin.entity.Admin;
import com.example.lushudao_admin.mapper.AdminMapper;
import com.example.lushudao_admin.service.AdminService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 六星伊
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public List<Admin> login(String admin_acc , String admin_pwd){
        System.out.println(adminMapper.login(admin_acc, admin_pwd));
        return adminMapper.login(admin_acc , admin_pwd); }

    @Override
    public Admin loginCheckUserAcc(String admin_acc){
        return adminMapper.loginCheckUserAcc(admin_acc);}

    @Override
    public void updateAdmin(int admin_id, String admin_name, String admin_acc, String admin_pwd) {
        adminMapper.updateAdmin(admin_id,admin_name,admin_acc,admin_pwd);
        redisTemplate.delete(redisTemplate.keys("manageList" + "*"));
    }

    @Override
    public void delOneAdmin(int admin_id) {
        adminMapper.delOneAdmin(admin_id);
        redisTemplate.delete(redisTemplate.keys("adminList"+"*"));
    }

    @Override
    public void delectUser(int user_id) {
        adminMapper.delectUser(user_id);
        redisTemplate.delete(redisTemplate.keys("userList"+"*"));
    }

    @Override
    public void delectUserRelease(int scenic_release_id) {
        adminMapper.delectUserRelease(scenic_release_id);
        redisTemplate.delete(redisTemplate.keys("userReleaseList" + "*"));
    }

    @Override
    public void delectUserComment(int comment_id) {
        adminMapper.delectUserComment(comment_id);
        redisTemplate.delete(redisTemplate.keys("userCommectList" + "*"));
    }

    @Override
    public void delectScenic(int scenic_id) {
        adminMapper.delectScenic(scenic_id);
        redisTemplate.delete(redisTemplate.keys("scenicList" + "*"));
    }

    @Override
    public void delectAdmin(int admin_id) {
        adminMapper.delectAdmin(admin_id);
        redisTemplate.delete(redisTemplate.keys("manageList" + "*"));
    }


}
